<template>
    <view class="body" :class="page === '1' ? (isEdit!=='1'?'noBottom':'bigFont') : 'smallFont'">
        <u-toast ref="uToast"/>
        <u-collapse-item :open="true" class="firstItem" ref="basicRef">
            <view slot="title" class="u-page__title">项目信息</view>
            <BasicView :titleList="titleList"></BasicView>
        </u-collapse-item>
        <u-collapse-item :open="true" ref="materialRef">
            <view slot="title" class="u-page__title">物料信息</view>
            <MaterialView :data="data"></MaterialView>
        </u-collapse-item>
        <u-collapse-item :open="true" ref="labelInfo">
            <view slot="title" class="u-page__title">标签信息</view>
            <view class="u-collapse-content">
                <view class="common-body-ex">
                    <view class="add-content content-box">
                        <view class="common-list-ex content-list">
                            <label class="content-label">资源资产编码：</label>
                            <view class="content-value">{{labelCode.resourceAssetCode || '无'}}</view>
                        </view>
                    </view>
                    <view class="content-box">
                        <view class="common-list-ex content-list">
                            <label class="content-label">原标签ID：</label>
                            <view class="content-value" v-if="labelCode.labelId || labelCode.oldLabelId" style="color: #007AFF;"  @click="schemeert(labelCode.resourceAssetCode,labelCode.labelId|| labelCode.oldLabelId)">{{labelCode.labelId || labelCode.oldLabelId}}</view>
                            <view class="content-value" v-else>无</view>
                        </view>
                    </view>
                    <view class=" add-content content-box">
                        <view class="common-list-ex content-list">
                            <label class="content-label">新标签ID：</label>
                            <view class="content-value" style="display: flex;align-items: center" v-if="page!=='1'">
                                <text v-if="newId"  style="color: #D9001B;" type="text" :selectable="true">请点击扫描按键获取新签</text>
                                <text v-if="!newId" :selectable="true" style="color: #007AFF;" @click="schemeert(labelCode.resourceAssetCode,newIdCode)">{{newIdCode}}</text>
                                <image @click="scanCode()" style="width: 38rpx;height: 38rpx;margin-left: 10rpx" src="../../static/imges/扫描saomiaored.png" mode=""></image>
                            </view>
                            <view class="content-value" v-else>
                              <text :selectable="true" style="color: #007AFF;" @click="schemeert(labelCode.resourceAssetCode,labelCode.newLabelId)">{{labelCode.newLabelId}}</text>
                            </view>
                        </view>
                    </view>
                    <view class="content-box">
                        <view class="common-list-ex content-list">
                            <label class="content-label" style="width: 30%"><text class="colorRed">*</text>换签原因：</label>
                            <view class="content-value" style="height: 70rpx;flex: 1">
                                <picker @change="aPickerChange" :value="aIndex" :range="ftypeCode" range-key="name" v-if="(page!=='1')||(page === '1' && isPageEdit)">
                                    <input class="uni-input"  @focus="aPickerFocus" style="height: auto;padding-left: 20rpx;margin-left: -15rpx;" :value="selected1Type" type="text" placeholder="请选择换签原因" >
                                </picker>
                                <text :selectable="true" style="line-height: 70rpx" v-else>{{data.reason}}</text>
                            </view>
                        </view>
                    </view>
                    <view class="add-content content-box">
                        <view class="common-list-ex content-list" style="align-items: flex-start">
                            <label class="content-label" style="white-space: nowrap;margin-right:20rpx "><text class="colorRed">*</text>具体情况说明:</label>
                            <textarea v-model="remark" placeholder="请输入" style="height: 120rpx;font-size: 28rpx;padding: 10rpx" v-if="(page!=='1')||(page === '1' && isPageEdit)"/>
                            <text :selectable="true" v-else style="line-height: 1.5;font-size: 24rpx">{{data.remark}}</text>
                        </view>
                    </view>
                    <view class="content-box">
                        <view class="common-list-ex content-list" style="align-items: flex-start;">
                            <label class="content-label" style="width: 25%"><text class="colorRed">*</text>上传图片:</label>
                            <view class="common-list-a" style="display: flex;flex: 1;position: relative;padding-right: 32rpx;min-height:120rpx ">
                                <view style="display: flex;flex-wrap: wrap">
                                    <view style="position: relative;display: inline-block;" v-for="(image,index2) in uploadImageList" :key="index2">
                                        <image class="photo-image" :src="fileData(image)" :data-src="image"
                                               @tap="previewImage(image,index2,'01')" style="width: 120rpx;height: 120rpx;margin: 0 14rpx"></image>
                                        <image @click="delectImg(index2,'01')" class="photo-delete-btn" style="right: 0"
                                               src="../../static/imges/shanchu2.png" v-if="(page!=='1')||(page === '1' && isPageEdit)">
                                        </image>
                                    </view>
                                </view>
                                <u-icon name="plus" style="font-size: 36rpx;position: absolute;top: 16rpx;right: 0;background-color: #FFF" @click="uploadImage" v-if="(page!=='1')||(page === '1' && isPageEdit)"></u-icon>
                            </view>
                        </view>
                    </view>
                    <view v-if="page==='1'">
                      <view class="add-content content-box">
                        <view class="common-list-ex content-list">
                          <label class="content-label">换签人员：</label>
                          <view class="content-value">{{data.swapUserId}}</view>
                        </view>
                      </view>
                      <view class="content-box">
                        <view class="common-list-ex content-list">
                          <label class="content-label" style="width: 60%">换签人员所属公司：</label>
                          <view class="content-value">{{data.orgName}}</view>
                        </view>
                      </view>
                      <view class="add-content content-box">
                        <view class="common-list-ex content-list">
                          <label class="content-label">换签经纬度：</label>
                          <view class="content-value">{{data.longitude}},{{data.latitude}}</view>
                        </view>
                      </view>
                      <view class="content-box">
                        <view class="common-list-ex content-list">
                          <label class="content-label">换签申请时间：</label>
                          <view class="content-value">{{data.createTime}}</view>
                        </view>
                      </view>
                    </view>
                </view>
            </view>
        </u-collapse-item>
        <u-collapse-item :open="true" v-if="Sinformation" ref="labelRef">
            <view slot="title" class="u-page__title">贴签信息</view>
            <view class="u-collapse-content">
                <view class="common-body-ex">
                    <view class="common-list-a" style="background-color: #efefef">
                        <label class="common-list-b" style="display: flex;background-color: transparent">
                            <text><span  style="color: red;">*</span>贴签位置 :</text>
                        </label>
                        <text class="common-list-c" style="height: auto;background-color: transparent" type="text" :selectable="true" v-if="page!=='1'"><input type="text" v-model="Sticker"  placeholder="请输入贴签位置" style="font-size: 28rpx;" maxlength="80"/></text>
                        <view :selectable="true" v-else style="line-height: 70rpx">{{Sticker}}</view>
                    </view>
                    <view class="common-list-a">
                        <label class="common-list-b" style=""><text><span  style="color: red;">*</span>贴签照片 :</text></label>
                    </view>
                    <view class="common-list-a" style="padding: 15rpx;">
                        <scroll-view scroll-x="true" style="white-space: nowrap;width: 100%;" scroll-left="120"
                                     show-scrollbar="true">
                            <view class="photo-item"  v-for="(image,index2) in tupianList" :key="index2">
                                <image class="photo-image"  :src="fileData(image.fileUrl)" :data-src="image"
                                       @tap="previewImage(image,index2,'02')" style="width: 120rpx;height: 120rpx"></image>
                                <image @click="delectImg(index2,'02')" class="photo-delete-btn"
                                       src="../../static/imges/shanchu2.png" v-if="page!=='1'">
                                </image>
                            </view>
                            <view class="photo-item" v-if="showPhotoer && page!=='1'">
                                <image class="photo-image"  :src="require('@/static/imges/shangchuanimg.png')"
                                       style="width: 122rpx;height: 122rpx;"
                                       @click="showPhoto()"></image>
                            </view>
                        </scroll-view>
                    </view>
                </view>
            </view>
        </u-collapse-item>
        <jn-approval-detail :processInstID="workDetail.processInstID" v-if="page==='1'"></jn-approval-detail>
        <u-popup v-model="bottomShow" mode="bottom">
            <view style="height: 300rpx;">
                <view v-debounce="() => getCamera()" style="width: 100%;height: 100rpx;border-bottom: 1px solid #D3D3D3;text-align: center;line-height: 100rpx;">
                    <text style="font-size: 15px;">拍摄</text>
                </view>
                <view v-debounce="() => getSelectImg()" style="width: 100%;height: 100rpx;border-bottom: 1px solid #D3D3D3;text-align: center;line-height: 100rpx;">
                    <text style="font-size: 15px;">相册选择</text>
                </view>
                <view @click="cancelImg()" style="width: 100%;height: 100rpx;border-bottom: 1px solid #D3D3D3;text-align: center;line-height: 100rpx;">
                    <text style="font-size: 15px;">取消</text>
                </view>
            </view>
        </u-popup>
        <view>
            <button-view @finishNext="finishNext()" :workDetail="workDetail" :selectUser="selectUser" :titleList="titleList" :isPageEdit="isPageEdit" :reason="reasoner" :remark="remark" :uploadImageList="uploadImageList" v-if="page==='1' && isEdit === '1'" @popClose="handleBack({userName: '', userId: '' })"></button-view>
            <footer-btn :btn-list="btnList" @handleBtn="handleBtn" v-if="page!=='1'"></footer-btn>
        </view>
        <u-modal ref="uModal" v-model="showModal" :show-cancel-button="true" confirm-color="#eb4b4b" :title-style="{fontSize:'36rpx',paddingTop:'20rpx'}" @confirm="confirmModal" @cancel="cancelModal" :async-close="true" title="温馨提示">
            <view class="slot-content" style="padding: 20rpx 60rpx 20rpx 40rpx">
                <view style="color: #606266">换签有风险，操作需谨慎（原标签ID：
                    <text :selectable="true" style="color: #007AFF;word-break: break-all" @click="schemeert(labelCode.resourceAssetCode,labelCode.labelId)">{{labelCode.labelId}}</text>）
                </view>
            </view>
        </u-modal>
        <!-- 弹框 -->
        <u-popup
            :mask-close-able="false"
            :closeable="false"
            v-model="showPopup"
            @close="handleClose"
            mode="bottom"
            height="450rpx"
        >
            <view class="pop-box">
                <view class="my-form">
                    <u-form label-width="160">
                        <u-form-item
                            label="办理节点"
                            required
                        >
                            <u-input
                                v-model="form.nodeName"
                                type="select"
                                :disabled="true"
                                border
                            />
                        </u-form-item>
                        <u-form-item label="办理人员" required prop="roleName">
                            <u-input
                                :class="{ 'disabled-select': isDisabled }"
                                type="select"
                                v-model="form.userName"
                                :disabled="isDisabled"
                                placeholder="请选择人员"
                                @click="handleOpen"
                                border
                            />
                        </u-form-item>
                    </u-form>
                </view>
                <view class="btns">
                    <button class="pms-btn" plain="true" @click="cancelPop">
                        取消
                    </button>
                    <button
                        class="pms-btn plain"
                        plain="false"
                        @click="submit"
                    >
                        提交
                    </button>
                </view>
            </view>
        </u-popup>
    </view>
</template>

<script>
import BasicView from "@/inspur/changeLabel/components/basicView.vue";
import MaterialView from "@/inspur/changeLabel/components/materialView.vue";
import footerBtn from "@/component/basic/footerBtn.vue";
import ButtonView from "@/inspur/changeLabel/components/buttonView.vue";
import JnApprovalDetail from "@/component/jn/JnApprovalDetail.vue";
import {getGPS} from "@/inspur/utils/gpsUtil";
export default {
    components: {
      JnApprovalDetail,
        ButtonView,
        footerBtn,
        BasicView,
        MaterialView
    },
    data() {
        return {
            data:{},
            labelCode: {},
            titleList:{},
            ionerid:'', //当前项目ID
            newId:true, //是否显示请扫描提示信息
            newIdCode:'', //新的扫码结果
            aIndex:"",
            selected1Type:"",
            reasoner:"",
            ftypeCode:[
                {
                    key:"2",
                    name:"标签脱落且丢失"
                },
                {
                    key:"3",
                    name:"标签质量问题无法扫码识别"
                },
                {
                    key:"4",
                    name:"标签类型使用有误更换为规范类型"
                },
                {
                    key:"5",
                    name:"质量问题厂家更换实物"
                },
            ],
            remark:'',//具体情况说明
            bottomShow:false,   //上传图片
            showPhotoer:true,
            tupianList:[],
            uploadImageList:[],
            uploadType:'02', //上传图片、贴签照片区分
            btnList:[
                {
                    label:'确认',
                    method:'confirm',
                },
                {
                    label:'取消',
                    method:'cancel',
                },
            ],
            Sinformation:false,
            Sticker:"", //贴签位置
            showModal:false,
            flag:'', // 2辅材 1服务 3主材 4非外市电力电缆  和旧代码保持一致
            swapMode:'02',
            selectUser:{},
            workItemId:"",
            workDetail:{},
            page:'0', // 0 换签页  1 换签审核页
            isEdit:'1',
            showPopup:false,
            form:{
                nodeName:'',
                userName:'',
                userId:''
            },
            isDisabled:false,
            latitude:'',
            longitude:'',
            isPageEdit:false,
        }
    },
    watch:{
        tupianList(){
            console.log("有无数据000",this.tupianList.length)
            if(this.tupianList.length==0){
                this.showPhotoer=true;
            }else{
                this.showPhotoer=false;
            }
        }
    },
    onLoad(option) {
        uni.setNavigationBarTitle({
            title: option.page === '1' || option.type === 'todo' ? '换签审核' : '换签页'
        });
        //审核页，需要嵌套审批信息，获取当前项目阶段
        if(option.page === "1" || option.type === 'todo' ){
            if(option.type === 'todo'){
                this.isEdit='1';
                this.page='1';
            }else{
                this.isEdit=option.isEdit;
                this.page=option.page;
            }
            uni.setStorageSync("sysToken", option.sysToken)
            this.workItemId=option.workItemId;
            this.getWorkItemId()
        }else{
            this.page = option.page
            this.ionerid= option.prjId
            let item = option.item ? JSON.parse(decodeURIComponent(option.item)) : {}
            let item1 = option.item1 ? JSON.parse(decodeURIComponent(option.item1)) : {}
            let item2 = option.item2 ? JSON.parse(decodeURIComponent(option.item2)) : {}
            this.flag = option.index
            this.data = item //物料信息
            this.labelCode = item1 //可以取标签、资源资产编码
            this.titleList = item2 //项目信息
            this.getZyUserInfo()
            //获取是否展示贴签位置和图片
            this.Permissioner()
        }
    },
    methods:{
        finishNext(){
            //审核流程结束，需要推送资源
            this.listerqe(this.data.latitude,this.data.longitude);
        },
        handleOpen(){
            uni.navigateTo({
                url: `/inspur/changeLabel/components/peopleList?peopleType=2&userId=`+this.form.userId+`&swapRole=`+this.titleList.loginRole+`&prjId=`+this.ionerid,
            });
        },
        getViewType(){
            if(+this.flag === 1 && +this.data.specState === 1){
                return '2'
            }else{
                return this.flag;
            }
        },
        submit(){
            if(!this.form.userName){
                this.$refs.uToast.show({
                    title: "请选择办理人员",
                    type: "error",
                    isTab: true,
                });
                return;
            }
            const params={
                prjId:this.ionerid,
                resourceAssetCode:this.labelCode.resourceAssetCode,
                oldLabelId:this.labelCode.labelId,
                newLabelId:this.newIdCode,
                swapMode:this.swapMode,
                isFromPhoto:1,
                reason:this.reasoner,
                labelLocation:this.Sinformation ?this.Sticker:"",
                labelPhotoId:this.Sinformation ?this.tupianList[0].fileUrl:"",
                remark:this.remark,
                uploadImageList:this.uploadImageList,
                latitude: this.latitude,
                longitude: this.longitude,
                viewType:this.getViewType(),
                prjName:this.titleList.prjName || this.titleList.projectName,
                nextAuditUserAccount:this.form.userId,
                categoryCode:this.data.categoryCode,
                categoryName:this.data.categoryName,
                swapRole:this.titleList.loginRole,
                osDetailId:this.data.osDetailId || '',
            }
            this.$axios.post('/material/api/flows/swapLabelFlow/startSwapLabelFlow',params).then(()=>{
                let pages = getCurrentPages();
                let prevPage = pages[pages.length - 2];
                prevPage.$vm.schoolNameert = this.flag;
                uni.navigateBack({
                    delta: 1
                })
            })
        },
        cancelPop(){
            this.showPopup=false;
            this.handleClose()
        },
        handleClose(){
            this.form.userName='';
            this.form.nodeName='';
            this.form.userId='';
        },
        getWorkItemId(){
            this.$axios.get('/acceptance/api/accept/commonAcceptance/getWFWorkItem',{workItemId:this.workItemId}).then((res)=>{
                this.workDetail=res.data;
                this.ionerid= res.data.bizObject?.bizSeq;
                this.getProjectInfo(res.data.bizObject?.bizSeq)
                if(this.isEdit === '1'){
                    this.getIsPageEdit(res);
                    this.getZyUserInfo()
                }
            })
        },
        //判断是否是第一个流程节点
        getIsPageEdit(res){
            const data ={
                processInstId: res.data.processInstID,
                actInsetId: res.data.activityInstID,
                route: '',
                excludeActDefIds: ''
            }
            this.$axios.post('/settlement/api/flow/getBackNextStepPerson',data).then((result)=>{
                if(result.data?.length > 0){
                    this.isPageEdit=false
                }else{
                    this.isPageEdit=true
                }
            })
        },
        getProjectInfo(bizSeq){
            this.$axios.post('/material/api/flows/swapLabelFlow/querySwapLabelInfo?bizSeq='+bizSeq).then((res)=>{
                this.data = res.data //物料信息
                this.labelCode = res.data //可以取标签、资源资产编码
                this.titleList = res.data //项目信息
                this.flag = res.data?.viewType
                this.uploadImageList=res.data?.uploadImageList
                this.ionerid= res.data?.prjId
                this.selected1Type=res.data.reason
                this.reasoner=res.data.reason
                this.remark=res.data.remark
                this.newIdCode=res.data.newLabelId
                this.Sticker=res.data.labelLocation
                this.tupianList.push({
                    fileUrl:res.data.labelPhotoId,
                })
                //获取是否展示贴签位置和图片
                this.Permissioner()
                this.$nextTick(()=>{
                    this.$refs.basicRef.init();
                    this.$refs.materialRef.init();
                    this.$refs.labelInfo.init();
                })
            })
        },
        getZyUserInfo(){
          this.$axios.get('/material/api/app/mainMaterialLable/getUserInfo',{prjId:this.ionerid}).then((res)=>{
            if(res.data){
              uni.setStorageSync("zyUserId", res.data.loginName);
              uni.setStorageSync("zyEmpName", res.data.name);
            }
          })
        },
        confirmModal(){
            this.showModal=false
            getGPS('', '', this.changeCode);
        },
        cancel(){
            uni.navigateBack({
                delta: 1
            });
        },
        getDisabled(){
            if(+this.titleList?.fieldProManState === 1){
                this.isDisabled = true
                this.form.userName= this.titleList?.fieldProManName+'('+this.titleList?.fieldProManAccount+')';
                this.form.userId=this.titleList.fieldProManAccount;
            }
        },
        confirm(){
            console.log(this.uploadImageList)
            this.$refs.uModal.clearLoading();
            if(this.Sinformation){
                if(this.Sticker==""){
                    uni.showModal({
                        title: '温馨提示',
                        content: "物料编码已赋码成功，请填写贴签位置",
                        showCancel: false,
                        confirmColor: '#eb4b4b',
                    })
                    return
                }
                if(this.tupianList.length==0){
                    uni.showModal({
                        title: '温馨提示',
                        content: "物料编码已赋码成功，请上传贴签照片",
                        showCancel: false,
                        confirmColor: '#eb4b4b',
                    })
                    return
                }
            }
            this.onOkConfirm();
        },
        onOkConfirm(){
            if(this.selected1Type){
                this.onOkConfirmOne();
            }else{
                uni.showModal({
                    title: '温馨提示',
                    content: "请选择换签原因",
                    showCancel: false,
                    confirmColor: '#eb4b4b',
                })
            }
        },
        onOkConfirmOne(){
            if(this.remark==""){
                uni.showModal({
                    title: '温馨提示',
                    content: "请填写具体情况说明",
                    showCancel: false,
                    confirmColor: '#eb4b4b',
                })
                return
            }
            if(this.uploadImageList.length==0){
                uni.showModal({
                    title: '温馨提示',
                    content: "请上传图片",
                    showCancel: false,
                    confirmColor: '#eb4b4b',
                })
                return
            }
            if(this.labelCode.labelId === this.newIdCode){
              uni.showModal({
                title: '温馨提示',
                content: "新标签与旧标签相同，请重新扫码",
                showCancel: false,
                confirmColor: '#eb4b4b',
              })
              return
            }
            this.showModal=true;
        },
        cancelModal(){
            this.showModal=false;
            console.log('取消')
        },
        toSignChangeimg(){
            if(this.page !== '1'){
                const labelId = this.labelCode.labelId || this.labelCode.oldLabelId
                this.$axios.post('/material/api/app/mainMaterialLable/queryLabelDetail?osDetailId='+this.data.osDetailId+"&labelId="+labelId+"&sourceAssetCode="+this.labelCode.resourceAssetCode).then((res)=>{
                    if(res.data){
                        this.Sticker=res.data.labelLocation
                        this.tupianList.push({
                            fileUrl:res.data.labelPhotoId,
                        })
                        this.$nextTick(()=>{
                            this.$refs.labelRef.init()
                        })
                    }
                })
            }
        },
        Permissioner() {
            this.$axios.post('/material/api/app/mainMaterialLable/isVirtualOrRoom?prjId='+this.ionerid).then((res)=>{
                if(res.data && +this.flag !== 2){
                    this.getPermission();
                }
            })
        },
        getPermission(){
            if(+this.flag === 1){
                if(this.data.specState!=1){
                    this.Sinformation=true;
                    this.toSignChangeimg()
                }
            }else{
                this.Sinformation=true;
                this.toSignChangeimg()
            }
        },
        // 上传照片
        showPhoto() {
            console.log("获取的值==" );
            this.bottomShow = true;
            this.uploadType = '02'
        },
        handleBtn(methodName) {
            this[methodName]()
        },
        //input禁止发起键盘调用
        aPickerFocus() {
            uni.hideKeyboard()
        },
        //选择换签原因
        aPickerChange(e) {
            console.log("触发"+e.detail.value);
            this.aIndex = e.detail.value;
            this.selected1Type = this.ftypeCode[this.aIndex].name;
            this.reasoner=this.ftypeCode[this.aIndex].name;
        },
        // 点击标签跳转至经分系统
        schemeert(options,amger){
          console.log(options,amger)
            this.$axios.get('/material/api/pub/material/getOtherSysIpAndPort',{ sysCode:'jingFenSysIpAndPort'}).then((res)=>{
                imp.iWindow.open({url:`${res.data}/api/user/getRedirectToBcsystem?resourceAssetCode=${options}&elabelNum=${amger}`})
            })
        },
        //点击扫描获取新的标签ID
        scanCode(){
            let that = this
            imp.iBarCode.scan(function (result) {
                //直接调用接口
                console.log('扫码id==',result)
                if(that.newIdCode == result){
                    uni.showModal({
                        title: '温馨提示',
                        content: "请勿重复扫码",
                        showCancel: false,
                        confirmColor: '#eb4b4b',
                    })
                }else{
                    that.newIdCode = result // 新ID号
                }
            });
            this.newId = false  // 	切换 隐藏红色字体，显示ID号
        },
        //上传图片
        uploadImage(){
            this.bottomShow = true;
            this.uploadType = '01'
        },
        //调用MOA拍照
        getCamera() {
            this.bottomShow = false
            let that = this
            imp.iCamera.open(
                {
                    quality: 84, //图片质量
                    encodingType: imp.iCamera.EncodingType.JPEG, //图片格式
                },
                (successData)=> {
                    // console.log('这是拍照所所得：',successData);
                    var base64Top = 'data:image/jpg;base64,';
                    that.base64er= base64Top + successData.originalData;
                    that.fiwfwsfsferer(base64Top + successData.originalData)
                },
                (err)=> {
                    uni.showModal({
                        title: '温馨提示',
                        content: "相机调用失败",
                        showCancel: false,
                        confirmColor: '#eb4b4b',
                    });
                }
            );
        },
        //调用MOA相册
        getSelectImg() {
            this.bottomShow = false
            let that = this
            console.log('选择图片了：');
            var option = {
                quality: 84,
                encodingType: imp.iCamera.EncodingType.JPEG,
                sizeLimit:this.uploadType === '01'? 1024*20 : 1024*2,
                num:this.uploadType === '01'? 10 : 1,
            };
            var failed = (info) => {
                uni.showModal({
                    title: '温馨提示',
                    content: "相机调用失败",
                    showCancel: false,
                    confirmColor: '#eb4b4b',
                });
            };
            var success = (info) => {
                var base64Top = 'data:image/jpg;base64,'
                setTimeout(() => {
                    for (let i = 0; i < info.length; i++) {
                        that.fiwfwsfsferer(base64Top+info[i].thumbnailData)
                    }
                }, 300);
            };
            imp.iCamera.select(option, success, failed);
        },
        // 取消拍照
        cancelImg() {
            this.bottomShow = false
        },
        previewImage: function(index,e,flag) {
            let lister=[];
            if(flag === '02'){
                this.tupianList.forEach((item)=>{
                    lister.push(item.fileUrl)
                })
            }else{
                lister=this.uploadImageList;
            }
            let current=this.fileData(lister[e]);
            let urls=lister.map((item)=>{
                return this.fileData(item);
            })
            uni.previewImage({
                current,
                urls,
            })
        },
        delectImg(x,flag){
            console.log("删除图片",x)
            if(flag === '02'){
                this.tupianList.splice(x, 1)
                this.showPhotoer=true;
            }else{
                this.uploadImageList.splice(x, 1)
                this.$nextTick(()=>{
                    this.$refs.labelInfo.init();
                })
            }
        },
        fileData(url){
            return (window.location.protocol + "//" + window.location.host + process.uniEnv.BASE_JM+"/pic/openUrl?httpUrl="+ url)
        },
        fiwfwsfsferer(url){
            console.log("照片")
            uni.uploadFile({
                url: process.uniEnv.BASE_JM+"/pic/uploadFile",
                filePath: url,
                formData:{
                    docType:"A1102",
                    aiRecognitionType:"0",
                    supplierUserAccount:"hudf"
                },    //这里放多余参数
                name: 'file',
                header: {
                    'sysToken': uni.getStorageSync("sysToken"),
                },
                success: ((res) => {
                    let data=JSON.parse(res.data)
                    console.log("canshu11",data)
                    if(data.code=="200"){
                        if(this.uploadType === '02'){
                            this.showPhotoer=false;
                            this.tupianList.push({
                                fileUrl:data.data.innerHttpUrl,
                                imgid:data.data.fileId
                            })
                            this.showPhotoer=false;
                        }else{
                            this.uploadImageList.push(data.data.innerHttpUrl)
                            this.$nextTick(()=>{
                                this.$refs.labelInfo.init();
                            })
                        }
                    }else{
                        uni.showModal({
                            title: "温馨提示",
                            content:data.msg==null?"上传失败,请重新选择":data.msg,
                            showCancel: false,
                            confirmColor: '#eb4b4b',
                        });
                    }

                }),
                fail: ((err) => {
                    uni.hideLoading()
                }),
                complete: () => {
                    uni.hideLoading()
                }
            });
        },
        getParams(){
            let urls = ""
            let params= {
              prjId:this.ionerid,
              resourceAssetCode:this.labelCode.resourceAssetCode,
              oldLabelId:this.labelCode.labelId,
              newLabelId:this.newIdCode,
              swapMode:this.swapMode,
              isFromPhoto:1,
              reason:this.reasoner,
              labelLocation:this.Sinformation ?this.Sticker:"",
              labelPhotoId:this.Sinformation ?this.tupianList[0].fileUrl:"",
              remark:this.remark,
              uploadImageList:this.uploadImageList,
              latitude:this.latitude,
              longitude:this.longitude
            }
            //1是服务换签2是辅材换签3是主材
            if(+this.flag === 1){
                urls = "/material/api/app/serverLable/swapServConfirm"
            }else if(+this.flag === 3){
                urls = "/material/api/app/mainMaterialLable/swapConfirm"
            }else if(+this.flag === 2){
                urls = "/material/api/app/auxMaterial/swapAuxConfirm"
            }else{
                urls='/material/api/cableMateLabel/swapCable'
            }
            return {
                urls,
                params
            }
        },
        changeCode(a,b,latitude, longitude){
            //a,b是占位，没有实际意义
            console.log(a,b,latitude, longitude)
            if(!latitude || !longitude){
              uni.showModal({
                confirmColor: '#eb4b4b',
                title: '温馨提示',
                content: "未获取到经纬度，请重试！",
                showCancel: false,
              })
            }else{
              //最后一步  确认提交
              this.checkLatitudeLongitude(latitude, longitude)
            }
        },
        checkLatitudeLongitude(latitude,longitude){
          let latituder = parseFloat(latitude).toFixed(6);
          let longituder = parseFloat(longitude).toFixed(6);
          let that=this;
            let params={
                resourceAssetCode:this.labelCode.resourceAssetCode,
                prjId: this.ionerid,
                latitude: latituder,
                longitude: longituder,
                oldLabelId:this.labelCode.labelId,
                newLabelId:this.newIdCode,
            }
            this.$axios.post('/material/api/app/pubSwapLabel/swapLabelBeforeCheck',params).then((res)=>{
              if(res.data.beyondDistance <= res.data.distance){
                //进行次数判断  正常往下走
                that.checkMessage(res.data.swapCountTip,latituder,longituder);
              }else if(+res.data.strongOrWeakFlag === 2){
                //弱校验
                uni.showModal({
                  confirmColor: '#eb4b4b',
                  title: "站址经纬度校验",
                  content: `您当前经纬度（WGS84坐标系）为${longituder}，${latituder}，距站址${res.data.beyondDistance} m，已超出${res.data.distance} m的最大距离限制。\n是否继续本次换签操作？`,
                  success: (res1) => {
                    if (res1.confirm) {
                      //进行次数判断  正常往下走
                      that.checkMessage(res.data.swapCountTip,latituder,longituder);
                    } else {
                      console.log("用户点击否");
                    }
                  },
                });
              }else{
                //强校验
                uni.showModal({
                  confirmColor: '#eb4b4b',
                  showCancel: false,
                  title: "站址经纬度校验",
                  content: `您当前经纬度（WGS84坐标系）为${longituder}，${latituder}，距站址${res.data.beyondDistance} m，已超出${res.data.distance} m的限制，暂不允许进行换签操作。\n如需修改站址经纬度，请在资源系统进行修改`,
                });
              }
            })
        },
        checkMessage(str,latitude,longitude){
            let that=this;
            this.latitude=latitude;
            this.longitude=longitude;
            if(str){
              uni.showModal({
                confirmColor: '#eb4b4b',
                title: "温馨提示",
                showCancel: false,
                content: str,
                success: (res) => {
                    if(res.confirm){
                        if(+this.titleList.loginRole === 1){
                            that.form.nodeName = '标签管理员审核'
                        }else{
                            that.form.nodeName = '项目管理岗审核'
                            that.getDisabled()
                        }
                        that.showPopup=true
                    }else{
                        console.log('啥也不干')
                    }
                },
              })
            }else{
              this.changeCodeConfirm();
            }
        },
        confirmEnd(){
            const that=this;
            this.listerqe(this.latitude,this.longitude);
            uni.showModal({
                confirmColor: '#eb4b4b',
                title: '温馨提示',
                content: "换签成功",
                showCancel: false,
                success: () => {
                    // --------主要是以下代码---------
                    let pages = getCurrentPages();
                    let prevPage = pages[pages.length - 2];
                    prevPage.$vm.schoolNameert = that.flag;
                    uni.navigateBack({
                        delta: 1
                    })
                },
            })
        },
        changeCodeConfirm(){
          let obj=this.getParams();
          this.$axios.post(obj.urls,obj.params).then(()=>{
              this.confirmEnd()
          })
        },
        lister(){
            var urler=`${process.uniEnv.BASE_ZYSJK}`;
            uni.request({
                url:urler+"/appManagerController/getResourceReplaceLabelLog",
                method: 'POST',
                dataType: 'json',
                timeout: 10000 * 60,
                header: {},
                data: {
                    assetNo:this.labelCode.resourceAssetCode,
                    sysSource:""
                },
                success: (res) => {
                    uni.hideLoading();
                    uni.stopPullDownRefresh();
                },
                fail: (data, code) => {
                    uni.hideLoading();
                    uni.stopPullDownRefresh();
                    console.log('fail' + JSON.stringify(data));
                }
            });
        },
        listerqe(latitude,longitude){
            let lat = parseFloat(latitude).toFixed(6);
            let lon = parseFloat(longitude).toFixed(6);
            var urler=`${process.uniEnv.BASE_ZYSJK}`;
            // 原因   this.reasoner   是否保留原签   this.swapMode
            console.log("u000rler",`${process.uniEnv.BASE_ZYSJK}`)
            uni.request({
                url:urler+"/appManagerController/insertOuterResourceReplaceLabelLog",
                method: 'POST',
                dataType: 'json',
                timeout: 10000 * 60,
                header: {},
                data:
                    {
                        "resId":"",
                        "assetNo":this.labelCode.resourceAssetCode,
                        "action":"2",
                        "roles":uni.getStorageSync("roleser"),
                        "labelId":this.newIdCode,
                        "cityId":"",
                        "cityName":"",
                        "provinceId":"",
                        "provinceName":"",
                        "reason":this.reasoner,    //换签原因
                        "sysSource":"PMS",
                        "oldLabelId":this.labelCode.labelId,
                        "createLoginName":uni.getStorageSync("zyEmpName"),
                        "createOp":uni.getStorageSync("zyUserId"),
                        "reasonDesc":this.remark, //具体情况说明
                        "longitude":lon,
                        "latitude":lat
                    },
                success: (res) => {
                    uni.hideLoading();
                    var data = res.data;
                    var result = JSON.stringify(data)
                    if (data.resultStat == "000") {
                        this.lister();
                    } else {
                        console.log('接口数据:' + result);
                    }

                    uni.hideLoading();
                    uni.stopPullDownRefresh();

                },
                fail: (data, code) => {
                    uni.hideLoading();
                    uni.stopPullDownRefresh();
                    console.log('fail' + JSON.stringify(data));
                }
            });
        },
        handleBack(obj){
            this.selectUser=obj;
            //换签发起 直接赋值
            if(this.page !== '1'){
                this.form.userName=obj.name
                this.form.userId=obj.id
            }
        }
    }
}
</script>
<style>@import "@/common/common-ui.css";</style>
<style>@import "@/common/uView.css";</style>
<style scoped lang="scss">
.body {
    width: 100%;
    box-sizing: border-box;
    background: #f7f8fa;
    padding:20rpx 20rpx 150rpx;
}
.disabled-select {
    pointer-events: none;
    background: rgba(220, 223, 230, 0.3);
}
.bigFont{
    .u-page__title{
        font-size: 36rpx;
    }
}

.smallFont{
    .u-page__title{
        font-size: 32rpx;
    }
}
.noBottom{
    padding:20rpx !important;
}
.firstItem{
    margin-top: 20rpx !important;
}
.add-content{
    background: #efefef;
}
.content-box{
    padding:6rpx 20rpx
}
.content-list{
    justify-content: space-between;
    align-items: center;
    height: auto;
}
.content-label{
    font-size: 28rpx;
    white-space: nowrap;
    width: 240rpx
}
.content-value{
    font-size: 24rpx;
    text-align: right;
    word-break: break-all
}
.common-list-a{
    width: 100%;
    overflow: hidden;
    /* height: 45px; */
    /* line-height: 40px; */
    //font-size: 18px;
    color: #333333;
    display: flex;
    margin-bottom: 5px;
    .common-list-b{
        width: 30%;
        height: auto;
        padding:10rpx 0 10rpx 14rpx;
        background-color: white;
        display: flex;
        font-size: 28rpx;
        /* align-items: center; */
        justify-content: space-around;
        flex-direction: column;
    }
    .common-list-c{
        width: 78%;
        padding:20rpx 10rpx 20rpx 10rpx;
        background-color: #00000008;
        height: auto;
        padding:10rpx 0 10rpx 14rpx;
        display: flex;
        justify-content: space-around;
        flex-direction: column;
    }
}
.photo-item {
    width: 24%;
    display: inline-block;
    position: relative;
}
.photo-image {
    width: 140rpx;
    height: 140rpx;
    margin:0px 20px;
}
.photo-delete-btn {
    width: 20px;
    height: 20px;
    position: absolute;
    top: 0rpx;
    right: 34rpx;
}
.pop-box {
    padding: 20rpx;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    height: 100%;
}
.my-form {
    width: 100%;
    padding: 40rpx 40rpx 20rpx;
}
.btns {
    display: flex;
    background: #fff;
    font-size: 12rpx;
}
.pms-btn {
    height: 60rpx;
    min-width: 130rpx;
    line-height: 60rpx;
    border-radius: 60rpx;
    color: #ca171d;
    border-color: #ca171d;
    margin: 20rpx 6rpx;
    font-size: 24rpx;
    &.plain {
        color: #fff;
        background: #ca171d;
    }
}
</style>
